import React, { Component } from 'react'

const Loadable = ({
  loader,
  loading: Loading
}) => {
  return class LoadableComponent extends Component {
    state = {
      LoadedComponent: null
    }

    componentDidMount() {
      // import('./Dashboard')
      loader().then(res => {
        // console.log(res.default)
        this.setState({
          LoadedComponent: res.default
        })
      })
    }

    render() {
      const { LoadedComponent } = this.state
      return (
        LoadedComponent ? <LoadedComponent /> : <Loading />
      )
    }
  }
}

export default Loadable
